package com.titaniume.pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @ProjectName: juc
 * @Package: com.titaniume.pool
 * @ClassName: ThreadPoolDemo1
 * @Author: huangrenfei
 * @Description:  演示三种类型的线程池
 * @Date: 2021/11/25 10:06
 * @Version: 1.0
 */
public class ThreadPoolDemo1 {
    public static void main(String[] args) {

        //一池n线程
        ExecutorService threadPool1 = Executors.newFixedThreadPool(5);  //5个窗口

        //一池一线程
        ExecutorService threadPool2 = Executors.newSingleThreadExecutor();

        //不确定线程数量，根据提交数量自动切换线程
        ExecutorService threadPool3 = Executors.newCachedThreadPool();


        try {
            //10个客户来办理业务
            for (int i = 1; i <=100; i++) {
                //执行
                threadPool3.execute(()->{
                    System.out.println(Thread.currentThread().getName() +"正在办理业务");
                });
            }
        } finally {
            //关闭线程池
            threadPool3.shutdown();
        }
    }
}
